package com.jinyijia.api.rest.v1;

import com.jinyijia.api.infrastructure.UserInfoManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import java.security.Principal;

/**
 * @author yangrd
 * @date 2018/8/3
 **/
@RestController
@RequestMapping("/test")
public class TestController {

    @Autowired
    private RestTemplate restTemplate;

    @GetMapping
    public String test() {
        return "i am android api";
    }

    @GetMapping("/brands")
    public Object listBrands() {
        return restTemplate.getForObject("http://brand-service/brands", Object.class);
    }

    @GetMapping("/me")
    public Object getCurrentUser(){
        return  UserInfoManager.getCurrentUsername();
    }

    @GetMapping("/i")
    public Object getCurrentUser(Principal principal){
        return principal;
    }
}
